#ifndef IMAGEITEMDELEGATE_H
#define IMAGEITEMDELEGATE_H

#include <QStyledItemDelegate>

class ImageItemDelegate : public QStyledItemDelegate
{
public:
    ImageItemDelegate(QObject* parent = 0):QStyledItemDelegate(parent){ }
    //在委托类的paint中画图
    virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
    {
        QStyledItemDelegate::paint(painter,option,index);

        if(index.data(Qt::DisplayRole).canConvert<QPixmap>())
        {
            QPixmap pix = index.data(Qt::DisplayRole).value<QPixmap>();
            pix = pix.scaled(option.rect.size(),Qt::KeepAspectRatio);
            //auto pixRect = pix.rect();
            //painter->drawPixmap(option.rect.x(),option.rect.y(),pixRect.width(),pixRect.height(),pix);
            painter->drawPixmap(option.rect,pix);
        }
    }
};

#endif // IMAGEITEMDELEGATE_H
